package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.mapper.OrdersMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "订单相关接口")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 订单搜索
     */
    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单搜索")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult orders = ordersService.conditionSearch(ordersPageQueryDTO);
        return Result.success(orders);
    }
    /**
     * 取消订单
     */
    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单")
    public Result<String> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordersService.adminCancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 拒绝订单
     */
    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 查看订单
     */
    @GetMapping("/details/{id}")
    @ApiOperation(value = " 查看订单")
    public Result<OrderVO> lookOrder(@PathVariable Long id){
        OrderVO orderVO = ordersService.lookOrder(id);
        return Result.success(orderVO);
    }

    /**
     * 完成订单
     */

    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单")
    public Result<String> finishOrder(@PathVariable Long id){
        ordersService.finishOrder(id);
        return Result.success();
    }
    /**
     * 各个状态的订单数量统计
     */
    @GetMapping("/statistics")
    @ApiOperation(value = "各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO = ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }
    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation(value = "接单")
    public Result<String> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.confirm(ordersConfirmDTO);
        return Result.success();
    }
    /**
     * 派送订单
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation(value = "派送订单")
    public Result<String> delivery(@PathVariable Long id){
        ordersService.delivery(id);
        return Result.success();
    }
}
